/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tec.data.persistence.jdbc;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.ResultSet;


/**
 * @author Joe Choi
 */
class JDBCResultSetProxy implements InvocationHandler {
	private JDBCResultSetProxy(ResultSet resultSet) {
		this.resultSet = resultSet;
	}
	
	public static Object createProxy(ResultSet rset) {
		return Proxy.newProxyInstance( 
			JDBCResultSetProxy.class.getClassLoader(),
			new Class[] {JDBCResultSet.class},
			new JDBCResultSetProxy(rset)
		);
	}
	
	@Override
	public Object invoke(Object obj, Method method, Object[] args) throws Throwable {
		Object res = null;
		
		try {
			Method nativeMtd = resultSet.getClass().getMethod(method.getName(), method.getParameterTypes());
			nativeMtd.setAccessible(true);
			res = nativeMtd.invoke(resultSet, args);
		} catch(Exception e) {
			throw e;
		}
		return(res);
	}
	
	private ResultSet resultSet;
}
